<?php
class MntCorVehiculo extends AppModel {

	var $name = 'MntCorVehiculo';
	var $useTable = 'mant_cors_vehiculos';
	var $validate = array(
		'mant_cor_id' => VALID_NOT_EMPTY,
		'vehiculo_id' => VALID_NOT_EMPTY,
	);
	
	function delMntoCorVehiculo($mant_prev_id = null, $vehiculo_id = null, $fecha_inicio = null, $fecha_fin = null){
		$this->query("DELETE FROM mant_prevs_vehiculos 
					  WHERE mant_prev_id = '$mant_prev_id' AND vehiculo_id = '$vehiculo_id' 
					  AND fecha_inicio = '$fecha_inicio', fecha_fin = '$fecha_fin'");
		return true;
	}
	
	function saveMntoCorVehiculo($data = null, $mant_prev_id = null, $vehiculo_id = null, $fecha_inicio = null, $fecha_fin = null, $km=null, $precio=null){
		$mant_prev_id_new = $data['MntCorVehiculo']['mant_prev_id'];
		$vehiculo_id_new = $data['MntCorVehiculo']['vehiculo_id'];
		$fecha_inicio_new = $data['MntCorVehiculo']['fecha_inicio'];
		$fecha_fin_new =  $data['MntCorVehiculo']['fecha_fin'];
		$this->query("UPDATE mant_prevs_vehiculos SET mant_prev_id = '$mant_prev_id_new', vehiculo_id = '$vehiculo_id_new', fecha_inicio = '$fecha_inicio_new', fecha_fin = '$fecha_fin', km = '$km', precio = '$precio' 
					  WHERE mant_prev_id = '$mant_prev_id' AND vehiculo_id = '$vehiculo_id' AND fecha_inicio = '$fecha_inicio' AND fecha_fin = '$fecha_fin'");
		echo "UPDATE mant_prevs_vehiculos SET mant_prev_id = '$mant_prev_id_new', vehiculo_id = '$vehiculo_id_new', fecha_inicio = '$fecha_inicio_new', fecha_fin = '$fecha_fin', km = '$km', precio = '$precio' 
					  WHERE mant_prev_id = '$mant_prev_id' AND vehiculo_id = '$vehiculo_id' AND fecha_inicio = '$fecha_inicio' AND fecha_fin = '$fecha_fin'";
		return true;		
	}

	function getMntoCorVehiculo($mant_prev_id = null, $vehiculo_id = null, $fecha_inicio = null, $fecha_fin = null)
	{
		$ret = $this->query("SELECT * FROM mant_prevs_vehiculos WHERE mant_prev_id = $mant_prev_id AND vehiculo_id = $vehiculo_id AND fecha_inicio = '$fecha_inicio' AND fecha_fin = '$fecha_fin'");
		return $this->adapt($ret);
	}

	function adapt($ret = null){
		$temp = $ret[0]['mant_prevs_vehiculos'];
		$data['MntoCorVehiculo']['mant_prev_id'] = $temp['mant_prev_id'];	
		$data['MntoCorVehiculo']['vehiculo_id'] = $temp['vehiculo_id'];
		$data['MntoCorVehiculo']['fecha_inicio'] = $temp['fecha_inicio'];
		$data['MntoCorVehiculo']['fecha_fin'] = $temp['fecha_fin'];
		$data['MntoCorVehiculo']['km'] = $temp['km'];
		$data['MntoCorVehiculo']['precio'] = $temp['precio'];
		return $data;	
	}
}
?>
